#include "BoaComponent.h"
#include "HelloWorldScene.h"
#include "Boa.h"
#include "cocos2d.h"
USING_NS_CC;


BoaComponent::BoaComponent()
{
    setName("Move");
    curAction = NULL;
	sizeScreen = CCDirector::sharedDirector()->getWinSize();
}


// Update trang thai cho con gian + goi cac ham callback o day
void BoaComponent::update(float delta)
{
	parent = (Boa*)getOwner();

	if (parent == NULL) return;


	//oldpos = parent->getPosition();

	//CCLog("%f", parent->getPositionX());

 //   if (parent == NULL) return;
	//
	//if(parent->getStatus() == ESCAPE)
	//{
	//	CCLog("++++++Tron thoat");
	//	parent->updateEscape(); // Cap nhat so gian tron thoat
	//	actionStop(); // Stop all action
 //       return;
	//
	//}

	//// DEATH CALL BACK, TRON THOAT CUNG HET PHIM
 //   if (parent->getStatus() == DEATH) // Chet la het PHIM
 //   {
	//	actionStop(); // Stop all action
 //       return;
 //   }
	//// RUN callback
 //   else if (parent->getStatus() == RUN)
 //   {
 //       actionRun();//nhay len va roi xuong
 //   }
	//else if (parent->getStatus() == RUNNING)
	//{
	//	return;
	//}
	//// IDLE callback funtion
	//else if (parent->getStatus() == IDLE)
 //   {
 //       actionIdle(); //cam dau xuong dat...
 //   }

	

}

// Ham di chuyen cua con gian
// Con gian se chay tu tren xuong duoi voi toc do tang theo level
void BoaComponent::actionCrawling()
{
    //truoc khi nhay len => stop action truoc...
	if(curAction)
	{
		actionStop();
	}
	// Thuc hien action RUN
}



void BoaComponent::actionBite()
{
	//CCLog("Trang thai bat dau cua con gian");
	// Hieu ung faceIn luc con gian xuat hien
	//parent->fCockRoachAppear();

}

void BoaComponent::actionBodyFly()
{
	
}

void BoaComponent::actionBiteFly()
{

}

void BoaComponent::actionStop()
{
    if (curAction != NULL)
    {
        parent->stopAction(curAction);
        curAction = NULL;

    }
}

// Thuc hien hanh dong di chuyen cua con khi
void BoaComponent::fBoaMoveTo(CCPoint p)
{
	
}


// Action Death callback -> thuc hien viec thay the anh va tao ra cac hieu ung chet
void BoaComponent::fCallbacktemp(CCObject * object){
	CCLOG("CALL back");
	//((Boa * ) object)->setStatus(RUN);
}